package com.edu.v2.compile.parser;

import com.edu.compile.Parser;
import org.apache.commons.lang3.StringUtils;

/**
 * @author zhanshen zhanshen.xu@tuya.com
 * @class FullBooleanParser
 * @since 2021/7/30
 */
public class BooleanParser implements Parser {

    @Override
    public Object parse(Object value) {
        if (value == null) {
            return null;
        }
        if (value instanceof Boolean) {
            return value;
        }
        String valueStr = value.toString();
        if (StringUtils.isEmpty(valueStr)) {
            return null;
        }
        return Boolean.valueOf(valueStr);
    }
}
